package com.diankangwo.factory.controller;

import com.diankangwo.common.utils.PageUtils;
import com.diankangwo.common.utils.Query;
import com.diankangwo.common.utils.R;
import com.diankangwo.factory.entity.TdCity;
import com.diankangwo.factory.entity.TdDiscuss;
import com.diankangwo.factory.entity.TdDistrict;
import com.diankangwo.factory.entity.TdProvince;
import com.diankangwo.factory.service.TdCityService;
import com.diankangwo.factory.service.TdDistrictService;
import com.diankangwo.factory.service.TdProvinceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by wuye on 2017/9/15.
 */
@RestController
@RequestMapping("/fac/pro")
public class TdProvinceController {

    @Autowired
    private TdProvinceService  tdProvinceService;

    @Autowired
    private TdCityService tdCityService;

    @Autowired
    private TdDistrictService tdDistrictService;


    /**
     * 获取省份列表
     */
    @ApiOperation(value = "获取省份列表",notes = "")
    @ApiImplicitParam(name = "params",value = "查询条件",required = true,dataType = "Map<String,Object>")
    @RequestMapping("/list")
    @RequiresPermissions("fac:pro:list")
    public R list(@RequestParam Map<String, Object> params){
        List<TdProvince> tdProvince = tdProvinceService.queryAll();
        return R.ok().put("province", tdProvince);
    }

    /**
     * 根据省份获取城市
     */
    @ApiOperation(value = "根据省份获取城市",notes = "")
    @ApiImplicitParam(name = "proId",value = "省份ID",required = true,dataType = "Integer")
    @RequestMapping("/queryByPro")
    @RequiresPermissions("fac:pro:queryByPro")
    public R queryByPro(int proId){
       List<TdCity> tdCities = tdCityService.queryByProvinceId(proId);
        return R.ok().put("tdCities", tdCities);
    }

    /**
     * 根据城市获取街道
     */
    @ApiOperation(value = "根据城市获取街道",notes = "")
    @ApiImplicitParam(name = "cityId",value = "城市ID",required = true,dataType = "Integer")
    @RequestMapping("/queryByCity")
    @RequiresPermissions("fac:pro:queryByCity")
    public R queryByCity(int cityId){
        List<TdDistrict> tdDistricts = tdDistrictService.queryByCityId(cityId);
        return R.ok().put("tdDistricts", tdDistricts);
    }
}
